#pragma once
#include <iostream>
#include <functional>
#include <thread>
#include <windows.h>
#include "pdh.h"
#include "..\..\..\thirdparty\nvml\include\nvml.h"
#include "StringTool.h"

#pragma comment(lib,"pdh.lib")

using CallbackSysInfo = std::function<void(std::string time,int pct_cpu,int pct_memory,int pct_gpu, ULARGE_INTEGER freeDisk, ULARGE_INTEGER totalDisk)>;

class SysInfo
{
public:

	static SysInfo* Inst()
	{
		static SysInfo single;
		return &single;
	}

	~SysInfo()
	{
		nvmlShutdown();
	}

	void StartWork();
	void StopWork();
	int GetGpuDevCount()
	{
		//return 5;
		return mGpuDevCount;
	}

	int getUsage_Memory();	
	int getUsage_GPU();	
	double getUsage_CPU_v2();
	void getDiskInfo(uint64_t& ulFree, uint64_t& ulTotal);

	CallbackSysInfo mSysInfoCb;

private:
	SysInfo()
	{
		mIsRunning = false;
		mGpuDevCount = 0;
		CPU2_Init();
		InitNvml();
	}

	void function_work();
	void CPU2_Init();

	//GPU
	int InitNvml();

	//not use
	int getUsage_CPU();

private:
	
	std::thread mThread;
	bool mIsRunning;

	//cpu
	FILETIME mPreIdleTime;
	FILETIME mPreKernelTime;
	FILETIME mPreUserTime;

	//cpu method 2
	PDH_HQUERY cpuQuery;
	PDH_HCOUNTER cpuTotal;

	//GPU
	unsigned int mGpuDevCount;
};

